<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="lib/vue.global.js"></script>
  <style>
    .modal {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: rgba(0, 0, 0, 0.5);
      display: flex;
      justify-content: center;
      align-items: center;
    }
  </style>
</head>
<body>
  <div id="root" style="position: relative;">
    <h3>Vue3中teleport</h3>
    <div>
      <modal-button></modal-button>
    </div>
  </div>
</body>
<script>
  const { createApp, ref } = window.Vue
  const ModalButton = {
    template: `
      <button @click="modalOpen = true">
          打开全屏的模态框
      </button>
      <teleport to="body">
        <div v-if="modalOpen" class="modal">
          <div>
            这是一个模态框
            <button @click="modalOpen = false">
              关闭
            </button>
          </div>
        </div>
      </teleport>
    `,
    setup(props) {
      const modalOpen = ref(false)
      return {
        modalOpen
      }
    }
  }

  const app = createApp({
    components: {
      ModalButton
    }
  })
  app.mount('#root')
</script>
</html>